package com.barry.pattern.interpreter;


public class ChineseExpression extends AbstractExpression {
	ChineseLiberty chineseLiberty;
	/**
	 * 分成一段段的翻译，减少堆栈长度。提高速度
	 */
	String[] beTranse;
	@Override
	public synchronized void express(String t) {
		//chineseLiberty使用单例，饿汉模式
		if (chineseLiberty==null) {
			synchronized (ChineseExpression.class) {
				if (chineseLiberty==null) {
					chineseLiberty=new ChineseLiberty();
					
				}
			}
		}
		System.err.println("翻译前："+t);
		this.beTranse=t.split(" ");
		super.express(t);
	}
	@Override
	public void run() {
		String result=""; 
		for (int i = 0; i < beTranse.length; i++) {
			result+= chineseLiberty.transToEn(beTranse[i]);
		}
		//输出翻译结果
		System.err.println("翻译结果："+result);
	}

}
